package com.seaengine.actor.node
{
	import com.seaengine.actor.Actor;
	import com.seaengine.actor.anibmp.AnimationBMPMgr;
	import com.seaengine.actor.anibmp.BaseBmpNodeInfo;
	import com.seaengine.actor.anibmp.characterbmp.CharacterFrameNodeInfo;
	import com.seaengine.core.timer.AnimationTimer;
	
	import flash.display.Bitmap;
	import flash.events.Event;
	import flash.events.TimerEvent;

	public class BaseNode extends Bitmap 
	{
		protected var m_NodeInfo:BaseBmpNodeInfo;
		protected var m_currentFrame:int;
		
		protected var m_actor:Actor;
				
		public function BaseNode(_actor:Actor)
		{
			m_actor = _actor;
		}
		
		/**
		 * 设置动画信息 
		 * @param _Info
		 * 
		 */
		public function setInfo(_Info:BaseBmpNodeInfo):void
		{
			m_NodeInfo = _Info ;
			m_currentFrame = 0;
				
		}
		
		/**
		 * 开始播放动作动画 
		 * 
		 */
		public function startAction():void
		{	
			trace("BaseNode.startAction()" + m_actor.actorName);
			m_currentFrame = 0;
			bitmapData = m_NodeInfo.m_animGrp[m_currentFrame];
			AnimationTimer.getInstance().addEventListener(TimerEvent.TIMER,onMoveFrame);
		}
		
		/**
		 * 停止播放动作动画 
		 * 
		 */
		public function stopAction():void
		{				
			AnimationTimer.getInstance().removeEventListener(TimerEvent.TIMER,onMoveFrame);		
			//bitmapData = null;
		}

		/**
		 * 监听AnimationTimer的TimerEvent
		 * @param event
		 * 
		 */
		protected function onMoveFrame(event:Event):void
		{
			trace("onMoveFrame  " + m_actor.actorName + "  m_currentFrame  " + m_currentFrame )
			if(m_currentFrame >= m_NodeInfo.m_animGrp.length )
			{
				HandleSthWhenFinishALoop(m_NodeInfo);			
				m_currentFrame = 0;
			}
			if(m_NodeInfo != null)
			{
				
				doEachFrame(m_NodeInfo.m_framesInfo[m_currentFrame]);
				if(bitmapData != m_NodeInfo.m_animGrp[m_currentFrame])
				{
					trace("change bitmapData  m_currentFrame  " + m_currentFrame   + m_actor.actorName)
					bitmapData = m_NodeInfo.m_animGrp[m_currentFrame];
				}
				HandleEffect();
				if(m_NodeInfo.m_framesInfo[m_currentFrame] is CharacterFrameNodeInfo){
						var nodeobj:CharacterFrameNodeInfo=m_NodeInfo.m_framesInfo[m_currentFrame] as CharacterFrameNodeInfo
					
					}
				m_currentFrame++;
				
			} 
		}
		
		private function doNextNode(_node:BaseBmpNodeInfo):void{
			if(_node == null )
			{
				return;
			}
			trace("BaseNode.doNextNode"  + m_actor.actorName)
			var obj:NodeWrapper=this.parent as NodeWrapper;
			obj.doActionByNode(_node);		
		}
		
		protected function HandleSthWhenFinishALoop(_info:BaseBmpNodeInfo):void
		{
			
		}
		protected function doEachFrame(_frameInfo:Object):void
		{
			
		}	
		protected function HandleEffect():void
		{
		} 	
	}
}